// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Evm.Precompiles;
using Nethermind.Specs.Forks;
using NUnit.Framework;
using System;

namespace Nethermind.Evm.Test;

public class BN254AddPrecompileTests
{
    [TestCase("089142debb13c461f61523586a60732d8b69c5b38a3380a74da7b2961d867dbf2d5fc7bbc013c16d7945f190b232eacc25da675c0eb093fe6b9f1b4b4e107b3625f8c89ea3437f44f8fc8b6bfbb6312074dc6f983809a5e809ff4e1d076dd5850b38c7ced6e4daef9c4347f370d6d8b58f4b1d8dc61a3c59d651a0644a2a27cf", "0a6678fd675aa4d8f0d03a1feb921a27f38ebdcb860cc083653519655acd6d79172fd5b3b2bfdd44e43bcec3eace9347608f9f0a16f1e184cb3f52e6f259cbeb", true)]
    [TestCase("23f16f1bcc31bd002746da6fa3825209af9a356ccd99cf79604a430dd592bcd90a03caeda9c5aa40cdc9e4166e083492885dad36c72714e3697e34a4bc72ccaa21315394462f1a39f87462dbceb92718b220e4f80af516f727ad85380fadefbc2e4f40ea7bbe2d4d71f13c84fd2ae24a4a24d9638dd78349d0dee8435a67cca6", "013f227997b410cbd96b137a114f5b12d5a3a53d7482797bcd1f116ff30ff1931effebc79dee208d036553beae8ca71afb3b4c00979560db3991c7e67c49103c", true)]
    [TestCase("0341b65d1b32805aedf29c4704ae125b98bb9b736d6e05bd934320632bf46bb60d22bc985718acbcf51e3740c1565f66ff890dfd2302fc51abc999c83d8774ba08ed1b33fe3cd3b1ac11571999e8f451f5bb28dd4019e58b8d24d91cf73dc38f11be2878bb118612a7627f022aa19a17b6eb599bba4185df357f81d052fff90b", "0e9e24a218333ed19a90051efabe246146a6d5017810140ef7e448030539038a230598b7d4127f5b4fd971820084c632ca940b29fcf30139cd1513bbbbf3a3dc", true)]
    [TestCase("279e2a1eee50ae1e3fe441dcd58475c40992735644de5c8f6299b6f0c1fe41af21b37bd13a881181d56752e31cf494003a9d396eb908452718469bc5c75aa8071c35e297f7c55363cd2fd00d916c67fad3bdea15487bdc5cc7b720f3a2c8b776106c2a4cf61ab73f91f2258f1846b9be9d28b9a7e83503fa4f4b322bfc07223c", "22f8aa414eb0b9b296bed3fb355804e92ec0af419d9906335f50f032d87a8bf82643f41b228310b816c784c2c54dcfadeaa328b792dbe0d0e04741cd61dac155", true)]
    [TestCase("0af6f1fd0b29a4f055c91a472f285e919d430a2b73912ae659224e24a458c65e2c1a52f5abf3e86410b9a603159b0bf51abf4d72cbd5e8161a7b5c47d60dfe571f752f85cf5cc01b2dfe279541032da61c2fcc8ae0dfc6d4253ba9b5d3c858231d03a84afe2a9f595ab03007400ccd36a2c0bc31203d881011dfc450c39b5abe", "1e51b9f09d8fc2e4ca11602326c2cfe191c6c6a47874526e80051197e9f6af842282e508ca489bf881e25cf9590151ff5cf94fa523683a0718d87abcc4d4a16f", true)]
    [TestCase("0e6eab4103302750b22364bd1ec80e5edfb3ad06fa175ff2517ca49489f728e9050a17b5a594d0fd6fafed7fe5c447793fe9b617f0f97c3ee6dd29638f6c9232038de98419e242685862c118253ab7df7358f863a59170c37e606d5bd23c742f076ff3443f4e01b7d7ace1315fe50cf77c365d8d289c65303bcc11ba7961ab95", "2231ab2eee93d63596f718533ddbb95a86b13d39e1162897d791566e797f82952f39ea566bede8e7ba15f3c61b0e96275b2fc51800ee2baf2f9bd7acfa874f0a", true)]
    [TestCase("1920c53c756f1ec1a40e0264e5f65808eafaeaa7b0885f89852297bc2186ac9d09416cc536a27b6d5616f74dd2bbbfb463b9961752e0aa38d47b5213994959ab015296293a5a1bb5e15a7d019787422cb3409e075e122c6fc5867f0c3f3715731782b870b6641d8d55323e27ebaea17909499877fda62e3ac1e2b2310cad5f9c", "0fa3236565b78b283f3ce63ca62bafb87c33407b11a077e39230ff37c054cf712a38174368bf872f80f78fb5222e95717183242b9d4da75c66243f043aed2fc5", true)]
    [TestCase("001faaf97b965ffa633612b7c8f9f4be0b286b19662e5cbe6878019d8ba1382b16567ced7a7ee5c272bbc378a95c2436fb0c6133649c77e55a708b28419b5cac0750d51706ced69621c8e4ba1758ba90c39ba8b3b50507bfa545ace1737e360e283d609cd67a291fc3d720c5b1113eececba4ca31d58a1319d6a5a2fa89608f9", "044fe3c480840e5a8f544efd28a8bf3246f0741a8c61c3116e93d84773399c8b26c5b695120cd724aa2a5f4dfd3042c07f752be4c4a8b750398109d80f4772eb", true)]
    [TestCase("128b65cb80257f3006fc20dbb6af6781da7e0f9213d2b909fd113ee0f2d2bb52251e288387db7be742fe67261f36a4f09eeb4763bbbaa1bb13af3dec65302a4115f64edf27478045bf45eded285544acaa7f2b3a2a36176acefc1a3d7181a73219d4344489688c2a2f16caf1141bc42021738339431b3a64cfbc293a73c1eddc", "0a20db61d2b74384ca184f20455ad1f380ba081f89e41c87ceb3fdbbba63c7aa1fbda20003ec799f306f70df7f53f91721e59353013ebf1647f5130903fff482", true)]
    [TestCase("16a9fe4620e58d70109d6995fe5f9eb8b3d533280cc604a333dcf0fa688b62e20b972bf2daef6c10a41db685c2417b6f4362032421c8466277d3271b6e8706a809ad61a8a83df55f6cd293cd674338c35dbb32722e9db2d1a3371b43496c05fa09c73b138499e36453d67a2c9b543c2188918287c4eef2c3ccc9ebe1d6142d01", "005a68cc13a108287aa3ca0bd8bef95096ef22668e15c87f7cbe0167cd1cdc930359b9b2dd28843838cf74cb4af2cfd656690a7f73de771b891142db22fa61fb", true)]
    [TestCase("0ef704cd9e3c0b10fbfdadae2fb02b1b8679d24684b9a8ced52d2890fb61453e20edded55ab925e685ff207c41edb00ea85eaf74918864a97d75924beb3e5d1c3431d14cfbe9a5a1244e88ada99303090b48f7580ae1e3aa0c82cd92025c03e41b1c9200304be38b893bd18ca5b528bb34fbcd8126c1104f0465a7ae1bf44556", "", false)]
    public void Test(string input, string output, bool status)
    {
        byte[] inputData = Convert.FromHexString(input);
        (byte[] outputData, bool outcome) = BN254AddPrecompile.Instance.Run(inputData, MuirGlacier.Instance);

        using (Assert.EnterMultipleScope())
        {
            Assert.That(outcome, Is.EqualTo(status));
            Assert.That(outputData, Is.EquivalentTo(Convert.FromHexString(output)));
        }
    }
}
